package admin.Controller;

import java.sql.SQLException;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import admin.DTO.ChartDTO;
import admin.Service.ChartServiceImpl;

@Controller
public class ChartController {
	private ChartServiceImpl serviceImpl;
	
	public ChartController(ChartServiceImpl serviceImpl){
		this.serviceImpl = serviceImpl;
	}
	@RequestMapping("/allshowchart.do")
	public ModelAndView AllShowChart(HttpServletResponse response,ChartDTO cto){
		ModelAndView mv = new ModelAndView();
	try{		 
		ChartDTO dto1 = serviceImpl.ShowAllChart();
		ChartDTO dto2 = serviceImpl.BadCount();
		ChartDTO dto3 = serviceImpl.GoodCount();
		mv.addObject("badcount", dto2.getBadcount());
		mv.addObject("goodcount", dto3.getGoodcount());
		mv.addObject("total", dto1.getTotal());
		mv.setViewName("main_Chart.ch");		
	}catch(SQLException e){
		e.printStackTrace();
		mv.addObject("error_message", e.getMessage());
		mv.setViewName("error");
	}
	return mv;
	}	
	
	
	@RequestMapping("/A.do")
	public ModelAndView A_Machine(HttpServletResponse response,ChartDTO cto){
		ModelAndView mv = new ModelAndView();
		
	try{
		ChartDTO dto1 = serviceImpl.ShowAllChartA();
		ChartDTO dto2 = serviceImpl.BadCountA();
		ChartDTO dto3 = serviceImpl.GoodCountA();
		mv.addObject("badcount", dto2.getBadcount());
		mv.addObject("goodcount", dto3.getGoodcount());
		mv.addObject("total", dto1.getTotal());
		mv.addObject("title","A차트");
		mv.setViewName("main_Chart.ch");	
	}catch(SQLException e){
		e.printStackTrace();
		mv.addObject("error_message", e.getMessage());
		mv.setViewName("error");
	}
	return mv;
	}
}
